package com.wu.cloudribbonfeign.fallback;

import com.wu.cloudribbonfeign.api.OrderApi;
import com.wu.common.entity.ResultData;
import feign.FeignException;
import feign.hystrix.FallbackFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @author whx
 * @date 2021/7/10
 */
@Component
public class OrderServerBackFactory implements FallbackFactory<OrderApi> {





    @Override
    public OrderApi create(Throwable throwable) {

        return new OrderApi() {
            @Override
            public ResultData orderList() {
                if(throwable instanceof FeignException.InternalServerError){
                    return new ResultData().FAIL("远程服务器访问500");
                }
                throwable.printStackTrace();
                return new ResultData().FAIL(throwable.getMessage());
            }

            @Override
            public ResultData orderGetById(@RequestParam("id") Integer id) {
                return null;
            }

            @Override
            public ResultData orderFindAll() {
                return new ResultData().FAIL(throwable.getMessage());
            }

            @Override
            public ResultData orderUpdate(int id) {
                return new ResultData().FAIL(throwable.getMessage());
            }
        };

    }
}
